package com.blue.wechat.invoke;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.blue.wechat.cache.Wechat;
import com.blue.wechat.cache.WechatCache;

/**
 * 获取微信接口令牌定时任务，调用频率不大于15分钟
 * 
 * @author zhengj
 * @since 1.0 2017年1月26日
 */
public class WechatAccessTokenTask
{
	private static Logger logger = LoggerFactory.getLogger(WechatAccessTokenTask.class);
	
	@Resource
	private WechatCache wechatCache;
	@Resource
	private WechatContainer wechatContainer;
	
	public WechatAccessTokenTask()
	{
	}
	
	public void task()
	{
		List<Wechat> wechatList = wechatCache.listAll();
		logger.info("准备更新微信接口令牌个数：{}", wechatList.size());
		
		for (Wechat wechat : wechatList)
		{
			wechatContainer.invoke(wechat.getCode(), WechatInvoker.ACCESS_TOKEN, null);
			wechatContainer.invoke(wechat.getCode(), WechatInvoker.JS_API_TICKET, null);
		}
	}
	
}
